/*
 * ImageRegistry.java
 * Created on August 12, 2008, 3:36 PM by Uru
 *
 * A registry system for 2D images
 * allows them to be referenced by string resource tags
 * also deals with memory and preprocessing issues (spritesheets and recolors)
 */

package ImageSystem;

import java.awt.*;
import javax.swing.*;
import java.awt.image.*;
import java.util.*;

public class ImageRegistry {
    protected static Hashtable<String,ImageData> nametable; //a table of images
    
    //initialize the stack with the first screen
    public static void initializeRegistry(){
        nametable = new Hashtable<String,ImageData>();
    }
    
    //register a new Image with the database
    public static void registerImage(String n, Image i){
        nametable.put(n,new ImageData(i));
    }
    
    //register a new Image with the using its filename
    public static void registerImage(String n, String file){
        nametable.put(n,new ImageData(file));
    }
    
    //get an image out of the registry
    public static Image getImage(String name){
        ImageData id = nametable.get(name);
        if(id != null){
            return id.getImage();
        }
        
        System.err.println("Could not find "+name+" in the image database");
        return null;
    }
    
    //draw an image in the registry
    public static void drawImage(String name, int x, int y, Graphics2D g, JComponent io){
        ImageData id = nametable.get(name);
        if(id != null){
            id.drawImage(x,y,g,io);
            return;
        }
        
        System.err.println("Could not find "+name+" in the image database");
    }
    
}
